﻿/*
4/17/2010 12:16:40 PM
*/


namespace LanSunSystem
{
    using System;
    using System.ServiceModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;

    public class ProcessPoint : QueryCommand
    {
        public ProcessPoint() : base() { }
        public ProcessPoint(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }
        public SqlCommand BuildCommand()
        {

            switch (RequestJob.Substring(6, 4))
            {
                case "0000":
                    /*
                         case "ProcessPoint":
                            ProcessPoint m_SProcessPoint = new ProcessPoint(cmdSQL, dtRequest, RequestJob);
                            cmdSQL = m_ProcessPoint.BuildCommand();
                            break;
                    */
                    break;
                case "1000":
                    break;
                case "2001":
                case "4000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
                case "1001":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    break;
                case "1002":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    break;
                case "1003":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    break;
                case "1004":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    break;
                #region GenerateTaskList
                /*
            DECLARE	@return_value int,
            @resultsql_1 nvarchar(max)
            EXEC	@return_value = [dbo].[GenerateTaskList]
            @table_name = N'ProcessPoint',
            @table_Short = N'GC',
            @tableid = N'*',
            @SysID = N'1',
            @conditions = N'1=2',
            @resultsql_1 = @resultsql_1 OUTPUT
  
                update ServiceList set Conditions='SysID=@SysID' where ServiceID='*1001';
                update ServiceList set Conditions='SysID=@SysID and GoodsTypeKey=@GoodsTypeKey' where ServiceID='*1002';
                update ServiceList set Conditions='SysID=@SysID and GoodsTypeKey=@GoodsTypeKey and GoodsTypeKeyDefKey=@GoodsTypeKeyDefKey' where ServiceID='*1003';
                update ServiceList set Conditions='SysID=@SysID and GoodsTypeKey=@GoodsTypeKey and GoodsTypeKeyDefKey=@GoodsTypeKeyDefKey and GoodsKey=@GoodsKey' where ServiceID='*1004';
              */
                #endregion
                case "2000":
                case "3000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    cmdSQL = BuildInstanceKey(cmdSQL, dwRequest);
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Source", dwRequest["Source"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyLevel", dwRequest["GoodsKeyLevel"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyID", dwRequest["GoodsKeyID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ProcessPointID", dwRequest["ProcessPointID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ProcessPointKey", dwRequest["ProcessPointKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsTypeKey", dwRequest["ParentGoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsTypeKeyDefKey", dwRequest["ParentGoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsKeyID", dwRequest["ParentGoodsKeyID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsKey", dwRequest["ParentGoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastPositionID", dwRequest["LastPositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ExtenedProperty", dwRequest["ExtenedProperty"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    break;
            }
            return cmdSQL;

        }
        public override SqlCommand BuildInstanceKey(SqlCommand cmdSQL, DataRow dwTemp)
        {

            string InstanceKey ="";
            string SysID = dwTemp["SysID"].ToString().Trim();
            string GoodsTypeKey = dwTemp["GoodsTypeKey"].ToString().Trim();
            string GoodsTypeKeyDefKey = dwTemp["GoodsTypeKeyDefKey"].ToString().Trim();
            string GoodsKey = dwTemp["GoodsKey"].ToString().Trim();
           
            {
                if (SysID != "" && GoodsTypeKey != "" && GoodsTypeKeyDefKey != "" && GoodsKey != "")
                {
                    InstanceKey = SysID + "." + GoodsTypeKey + "." + GoodsTypeKeyDefKey + "." + GoodsKey;
                    dwTemp["InstanceKey"] = InstanceKey;
                    dwTemp.AcceptChanges();
                }
            }
            cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
            return base.BuildInstanceKey(cmdSQL, dwTemp);
        }
    }
    public class ProcessPointQueryCond : QueryCommand
    {
        public ProcessPointQueryCond() : base() { }
        public ProcessPointQueryCond(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }

        public SqlCommand BuildCommand()
        {
            switch (RequestJob.Substring(6, 4))
            {
                case "0000": break;
                case "1000": break;
                case "1001": break;
                case "1002": break;
                case "2000":
                case "3000":
                    #region
                    /*
                USE [LANSUNERP]
                GO
                SET ANSI_NULLS ON
                GO
                SET QUOTED_IDENTIFIER ON
                GO
                SET ANSI_PADDING ON
                GO
				 DROP TABLE [dbo].[ProcessPointQueryCond]
                GO
                CREATE TABLE [dbo].[ProcessPointQueryCond](
                [QueryType] [nvarchar](50) NULL,[ConditionType] [nvarchar](50) NULL,[SysID] [nvarchar](10) NULL,
[InstanceID] [nchar](256) NULL,
[InstanceKey] [nchar](256) NULL,
[GoodsTypeKey] [nvarchar](2) NULL,
[GoodsTypeKeyDefKey] [nvarchar](5) NULL,
[Source] [nvarchar](20) NULL,
[GoodsKeyLevel] [int] NULL,
[GoodsKeyID] [nvarchar](50) NULL,
[GoodsKey] [nvarchar](50) NULL,
[ProcessPointID] [nvarchar](50) NULL,
[ProcessPointKey] [nvarchar](50) NULL,
[ParentGoodsTypeKey] [nvarchar](2) NULL,
[ParentGoodsTypeKeyDefKey] [nvarchar](5) NULL,
[ParentGoodsKeyID] [nvarchar](50) NULL,
[ParentGoodsKey] [nvarchar](50) NULL,
[LongDes] [nvarchar](40) NULL,
[ShortDes] [nvarchar](20) NULL,
[PositionID] [int] NULL,
[LastPositionID] [int] NULL,
[ExtenedProperty] [nvarchar](40) NULL,
[SubStatus] [varchar](10) NULL,
[Status] [varchar](10) NULL,
[FrstUser] [nvarchar](10) NULL,
[FrstDate] [datetime] NULL,
[LastUser] [nvarchar](10) NULL,
[LastDate] [datetime] NULL,
***
                )
                GO
                */
                    #endregion
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Source", dwRequest["Source"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyLevel", dwRequest["GoodsKeyLevel"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyID", dwRequest["GoodsKeyID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ProcessPointID", dwRequest["ProcessPointID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ProcessPointKey", dwRequest["ProcessPointKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsTypeKey", dwRequest["ParentGoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsTypeKeyDefKey", dwRequest["ParentGoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsKeyID", dwRequest["ParentGoodsKeyID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ParentGoodsKey", dwRequest["ParentGoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastPositionID", dwRequest["LastPositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ExtenedProperty", dwRequest["ExtenedProperty"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@FrstUser", dwRequest["FrstUser"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@FrstDate", dwRequest["FrstDate"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastUser", dwRequest["LastUser"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastDate", dwRequest["LastDate"].ToString()));

                    break;
                case "4000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
            }
            return cmdSQL;

        }

    }
}

